package define
{
	import flash.data.SQLConnection;
	import flash.data.SQLMode;
	import flash.filesystem.File;
	import flash.system.Capabilities;
	
	import mx.utils.Base64Decoder;
	
	import orm.armory.dao.RBossItem_DAO;
	import orm.armory.dao.RItemToken_DAO;
	import orm.armory.dao.RVendorSell_DAO;
	import orm.armory.dao.TblBoss_DAO;
	import orm.armory.dao.TblItemProperty_DAO;
	import orm.armory.dao.TblItem_DAO;
	import orm.armory.dao.TblVendor_DAO;
	import orm.iris.dao.RCharItem_DAO;
	import orm.iris.dao.TblCharacter_DAO;
	
	public class DBConst
	{			
		public static var armoryConn:SQLConnection = getArmoryConn();
//		public static var irisConn:SQLConnection = getIrisConn();
		
		private static function getArmoryConn():SQLConnection
		{
			var dbFile:File;
			// C:\Google Code\air-armory\trunk\flex-project\IrisArmory\db\airarmory.db
			// D:\Google Code\air-armory\trunk\flex-project\IrisArmory\db\airarmory.db
			if(Capabilities.language == "ja")
				;//dbFile = new File("C:/Google Code/air-armory/trunk/flex-project/IrisArmory/db/airarmory.db");
			else
				dbFile = new File("E:/12.Google Code/air-armory/Work Space/WowFantasy/asserts/db/fantasy_encrypted_zh_cn.db");
			
			
			var sqlConn:SQLConnection = new SQLConnection();
//			sqlConn.open(dbFile, SQLMode.UPDATE);
			var decoder:Base64Decoder = new Base64Decoder();
			decoder.decode("3tmYpPZpCG9IvN70Kk3cNw==");
			sqlConn.open(dbFile, SQLMode.CREATE, false, 1024, decoder.flush());
			
			RBossItem_DAO.getInstance().setConnection(sqlConn);
			RItemToken_DAO.getInstance().setConnection(sqlConn);
			RVendorSell_DAO.getInstance().setConnection(sqlConn);
			TblBoss_DAO.getInstance().setConnection(sqlConn);
			TblItem_DAO.getInstance().setConnection(sqlConn);
			TblItemProperty_DAO.getInstance().setConnection(sqlConn);
			TblVendor_DAO.getInstance().setConnection(sqlConn);
			
			return sqlConn;
		}
		private static function getIrisConn():SQLConnection
		{
			var dbFile:File;
			// C:\Google Code\air-armory\trunk\flex-project\Iris\db\iris.db
			// D:\Google Code\air-armory\trunk\flex-project\Iris\db\iris.db
			if(Capabilities.language == "ja")
				dbFile = new File("C:/Google Code/air-armory/trunk/flex-project/Iris/db/iris.db");
			else
				dbFile = new File("D:/Google Code/air-armory/trunk/flex-project/Iris/db/iris.db");
				
			var sqlConn:SQLConnection = new SQLConnection();
			sqlConn.open(dbFile, SQLMode.UPDATE);
			
			RCharItem_DAO.getInstance().setConnection(sqlConn);
			TblCharacter_DAO.getInstance().setConnection(sqlConn);
			
			return sqlConn;
		}

	}
}